package de.itagile.hypersphere

class EntiyRelationshipTemplateTest extends GroovyTestCase {
	def oneToOneRelationship = [fqn:"test.ejb.Author", type:"OneToOne", collection:""]
	def manyToManyRelationship = [fqn:"test.ejb.Author", type:"ManyToMany", collection:"java.util.Set"]
	def template = new EntityRelationshipTemplate()
	
	void testResolvesReturnTypeOfOneToOneRelationship() {
		assertEquals("test.ejb.Author", template.getReturnType(oneToOneRelationship))
	}
	
	void testResolvesReturnTypeOfManyToManyRelationship() {
		assertEquals("java.util.Set<test.ejb.Author>", template.getReturnType(manyToManyRelationship))
	}
	
	void testGeneratesField() {
		def result = template.relationshipField("RETURN_TYPE", "NAME")
		assertEquals("private RETURN_TYPE NAME;", result[0])
	}
	
	void testGeneratesGetter() {
		def result = template.relationshipGetter("TYPE", "RETURN_TYPE", "NAME")
		assertEquals("@TYPE", result[0])
		assertEquals("public RETURN_TYPE getNAME() {", result[1])
		assertEquals("return NAME;", result[2])
		assertEquals("}", result[3])
	}
	
	void testGeneratesSetter() {
		def result = template.relationshipSetter("TYPE", "RETURN_TYPE", "NAME")
		assertEquals("public void setNAME(RETURN_TYPE NAME) {", result[0])
		assertEquals("this.NAME = NAME;", result[1])
		assertEquals("}", result[2])
	}
}